<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div {
      font-size: 1.125rem;
      width: 31.25rem;
      height: 31.25rem;
      background: pink;
    }

    span {
      margin-top: 50px;
      display: inline-block;
      background: green;
      width: 200px;
      height: 200px;
      font-size: 16px;
    }
  </style>
</head>
<div>你好</div>
<span>你好</span>

<body>

  <script>
    function setHtmlFontSize() {
      let scrollWidth = document.documentElement.clientWidth;
      let rem = 0;
      if (scrollWidth < 900) {
        rem = 10;
      } else if (scrollWidth >= 900 && scrollWidth < 1200) {
        rem = 12
      } else if (scrollWidth >= 1200 && scrollWidth < 1600) {
        rem = 13
      } else if (scrollWidth >= 1600) {
        rem = 15;
      }
      document.documentElement.style.fontSize = rem + 'px';
      console.log(666);
    }
    function _render(fn) {
      if (document.addEventListener) {
        document.addEventListener('DOMContentLoaded', () => {
          fn();
          document.removeEventListener('DOMContentLoaded', fn, false)
        }, false)
      } else {
        document.attachEvent('onreadyStateChange', () => {
          if (document.readyState === 'complete') {
            fn();
            document.dettachEvent('onreadyStateChange', fn)
          }
        })
      }
    }

    _render(setHtmlFontSize);
    window.addEventListener('resize', setHtmlFontSize, false);
  </script>
</body>

</html>